const { Display, translateValue, translateAbility } = require("../../display/general");
const { ignoreIt } = require("../../util/ignore");
const { getModelType } = require("../../util/utils");
const { parseAbilityBehavior } = require("./behavior");

function parseAbility(a) {
    let result = {
        name: translateAbility(a.displayName.trim() ? a.displayName.trim() : a.addedViaUpgrade),
        cooldown: Display.time(a.cooldown),
        maxActivationCount: a.maxActivationsPerRound > 0 && a.maxActivationsPerRound < 9999 ? a.maxActivationsPerRound : null,
        liveCost: a.livesCost ? a.liveCost : null,
        projectile: [], // only for some special behaviors
        attacks: [],
        buffs: [],
        towers: [],
        behaviors: [],
        meta: {},
        notes: [
            a.canActivateBetweenRounds ? translateValue('canActivateBetweenRounds', 'can activate between rounds') : null,
            a.resetCooldownOnTierUpgrade ? translateValue('resetCooldownOnTierUpgrade', 'reset cooldown on upgrade') : null,
            a.restrictAbilityAfterMaxRoundTimer ? translateValue('restrictAbilityAfterMaxRoundTimer', 'can only activate in 3 min from round start') : null
        ]
    }
    a.behaviors.forEach(b => {
        const type = getModelType(b)
        if (ignoreIt(type)) return
        parseAbilityBehavior(b, result, type)
    });
    return result
}

module.exports = {
    parseAbility
}